<?php

namespace App\Model;


use Illuminate\Http\Request;

class PearlConsumeStatistics extends BaseModel
{
    protected $connection = 'mysql';
    protected $table = 'pearl_consume_statistics';
    public $timestamps = false;
    protected $fillable = [ 'gift_pearl', 'headwear_pearl','activity_pearl','car_pearl','bubble_pearl', 'today_', 'growth_rate', 'grand_diamond', 'created_date','smash_eggs_diamond' ];
    
    public function getGiftDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getHeadwearDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getCarDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getBubbleDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getSmashEggsDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getLotteryDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getActivityDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getTodayDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getGrandDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getSystemDiamondAttribute($value){
        return number_format($value);
    }
    
    public function getList(Request $request){
        $limit = $request->input('limit', 10);
        $page = $request->input('page', 1);
        $begin_date = $request->input('begin_date');
        $end_date = $request->input('end_date');
        
        $query = new self();
        
        if($begin_date && $end_date) $query = $query->whereBetween('created_date',[ $begin_date, $end_date ]);
        if($begin_date && !$end_date) $query = $query->where('created_date', '>=', $begin_date);
        if(!$begin_date && $end_date) $query = $query->where('created_date', '<=', $end_date);

        return $query->orderBy('id','DESC')->paginate($limit,['*'],'page',$page);
    }
}
